package edu.pku.sei.transformation.editor.parser.expression.element;

import edu.pku.sei.modeler.model.core.MetaModelElement;

public class OperationExpression extends Expression {
	private Expression leftExpression;
	private Expression rightExpression;
	private String operator;

	@Override
	public String toString() {
		String s = new String();
		if (leftExpression != null)
			s += leftExpression.toString() + " ";
		s += operator;
		if (rightExpression != null)
			s += " " + rightExpression.toString();
		return s;
	}

	public Expression getLeftExpression() {
		return leftExpression;
	}

	public void setLeftExpression(Expression leftExpression) {
		this.leftExpression = leftExpression;
	}

	public String getOperator() {
		return operator;
	}

	public void setOperator(String operator) {
		this.operator = operator;
	}

	public Expression getRightExpression() {
		return rightExpression;
	}

	public void setRightExpression(Expression rightExpression) {
		this.rightExpression = rightExpression;
	}

	// public Element toXML(Element root) {
	// Element ele = root.addElement("operation");
	// ele.addAttribute("operator", operator);
	// this.leftExpression.toXML(ele.addElement("left"));
	// this.rightExpression.toXML(ele.addElement("right"));
	// return ele;
	// }
	@Override
	public boolean bind(Object context) {
		return leftExpression.bind(context) && rightExpression.bind(context);

	}

	@Override
	public MetaModelElement getType() {
		return leftExpression.getType();
	}

	@Override
	public void sendHighLightNotify() {
		leftExpression.sendHighLightNotify();
		rightExpression.sendHighLightNotify();
	}

	@Override
	public void cancelHighLightNotify() {
		leftExpression.cancelHighLightNotify();
		rightExpression.cancelHighLightNotify();
	}

	@Override
	public void removeInvalidBinding() {
		leftExpression.removeInvalidBinding();
		rightExpression.removeInvalidBinding();
	}
}
